// pages/remind/remind.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageRoot: app.globalData.imageRoot,
    remind: [],
    page_token: 0,
    myl: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  query(data) {
    let that = this;
    getApp().ports.api35({ data}).then((res) => {
      // console.log(res)
      let datalist = res.data;
      datalist.results.forEach(item => {
        if(item.noticeType == 1){
          item.banner = item.foreclosedHouse.banner;
          if(!item.tags){
            let tags = [];
            tags.push({name:item.foreclosedHouse.builtUpAreaSquareCentimeter.toFixed(2)+"m²"})
            tags.push({name:item.foreclosedHouse.discountRate.toFixed(2)+"折"})
            if(item.foreclosedHouse.stage) tags.push({name:item.foreclosedHouse.stage})
            item.tags = tags
          }
          item.marketPriceYuan = Math.floor(item.foreclosedHouse.marketPriceYuan/10000)
          item.priceYuan = Math.floor(item.foreclosedHouse.priceYuan/10000)
          item.estimatePriceYuan = Math.floor((item.foreclosedHouse.estimatePriceYuan / 10000));
        }else{
          item.banner = that.data.imageRoot + item.discountHouse.banner;
          if(!item.tags){
            let tags = [];
            tags.push({name:item.discountHouse.builtUpAreaSquareCentimeter.toFixed(2)+"m²"})
            tags.push({name:item.discountHouse.discountRate.toFixed(2)+"折"})
            if(item.discountHouse.stage) tags.push({name:item.discountHouse.stage})
            item.tags = tags
          }
          item.marketPriceYuan = item.discountHouse.marketPriceYuan
          item.priceYuan = item.discountHouse.priceYuan
          item.estimatePriceYuan = Math.floor((item.discountHouse.estimatePriceYuan));
        }

        if(that.data.page_token >= 1){
          that.data.remind.results.push(item)
        }
      })
      if (that.data.page_token >= 1) {
        datalist.results = that.data.remind.results
      }
      this.setData({remind: datalist ,myl: false  })
      
    }).catch((error) => {
      console.log(error)
    })
  },
  onLoad: function (options) {
    wx.hideShareMenu({
      menus: ['shareAppMessage', 'shareTimeline']
    })
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: app.globalData.color,
    })
    // for(let i = 0;i<2;i++){
    //   let data = {foreclosed_house_id:"3b0c1bf4-7b4b-400c-b752-d00e8ef3debd"}
    //   getApp().ports.api355({data:data}).then((res) =>{
    //   }).catch((error)=>{console.log(error)});//测试用
    // }
    let data = { page_size: 10, page_token: this.data.page_token }
    this.query(data);
  },
  getdata(e) { //删除后刷新
    // console.log(e)
    if (e.detail.code == 200) {
      this.query()
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.query({});
    this.setData({
      page_token:0
    })
    setTimeout(()=>{
      wx.stopPullDownRefresh()
      console
    },1000)
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  // onReachBottom: function () {
  onReachBottom() { //上拉加载更多
    var that = this;
    //检查是否还有数据可以加载
    var total_size = that.data.remind.total;
    var size = that.data.remind.results.length;
    var page_token = that.data.page_token += 1; //每次下拉，页码加1
    //如果还有，则继续加载
    if (total_size > size) {
      var data = {
        page_token: page_token,
        page_size: 10
      }
      // that.data.Loading = wx.showLoading({ title: '加载中',  })
      that.query(data)
      //如果没有了，则停止加载，显示没有更多内容了
    } else {
      that.setData({
        myl: true
      })
    }
    that.setData({
      Loading: that.data.Loading
    })
  },
  // },

  
})